package com.lzw.bluetoothpractice.Adapters;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lzw.bluetoothpractice.Activitys.DetailForumActivity;
import com.lzw.bluetoothpractice.Activitys.HosptialDetailActivity;
import com.lzw.bluetoothpractice.AppConfig;
import com.lzw.bluetoothpractice.R;
import com.lzw.bluetoothpractice.bean.RecommendDoctorBean;
import com.lzw.bluetoothpractice.bean.RecommendHosptialBean;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class RecommendHosptialListAdapter extends RecyclerView.Adapter<RecommendHosptialListAdapter.ViewHolder>{
    private List<RecommendHosptialBean.DataBean> datas = new ArrayList<>();
    View itemView;
    Context mcontext;
    public void updateData(List<RecommendHosptialBean.DataBean> data) {
        if (this.datas == null) {
            this.datas = new ArrayList<>();
        }
        this.datas.clear();
        this.datas.addAll(data);
        notifyDataSetChanged();
    }
    public RecommendHosptialListAdapter(Context mcontext) {
        this.mcontext = mcontext;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
       // Glide.with(mcontext).load(sendMessage.getReceptUserHead()).into(holder.iv_head);
        RecommendHosptialBean.DataBean hosptialBean = datas.get(position);
        if (holder instanceof ViewHolder) {

            Glide.with(mcontext).load(AppConfig.BASE_URL+hosptialBean.getPic()).into(holder.iv_hosptialHead);

            ((ViewHolder) holder).hosptialName.setText(hosptialBean.getHospitalName());
        }

        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mcontext, HosptialDetailActivity.class);
                intent.putExtra("hosptialId",hosptialBean.getHospitalId()+"");

                mcontext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        itemView= LayoutInflater.from(mcontext).inflate(R.layout.recommend_hosptial,parent,false);

        return new ViewHolder(itemView);
    }

    class ViewHolder extends RecyclerView.ViewHolder {

    View view;

    ImageView iv_hosptialHead;
    TextView hosptialName;

    public ViewHolder(@NonNull View itemView) {
        super(itemView);
        view=itemView;
        iv_hosptialHead=view.findViewById(R.id.iv_hosptialHead);
        hosptialName=view.findViewById(R.id.hosptialName);





    }
}
}
